import xml.sax
import xml.sax.handler
import pprint


class XMLHandler(xml.sax.handler.ContentHandler):
    def __init__(self):
        self.CurrentName = ""
        self.error = ""
        self.status = 0
        self.zyddh = ""
        self.ygdm = ""

    def startElement(self, name, attributes):
        self.CurrentName = name

    def characters(self, data):
        if self.CurrentName == "ZYDDH":
            if self.zyddh !="":
                self.zyddh = self.zyddh +","
            self.zyddh = self.zyddh+data
        elif self.CurrentName == "Error":
            self.error = data
        elif self.CurrentName == "Status":
            self.status = data
        elif self.CurrentName == "YGDM":
            self.ygdm = data

    def endElement(self, name):
        pass

    def getDispatch(self):
        return  self.zyddh
    def getError(self):
        return  self.error
    def getYGDM(self):
        return  self.ygdm
    def isSuccess(self):
        if self.status =="0":
            return True
        else:
            return False

def getXMLHandler(str):
    xh = XMLHandler()
    xml.sax.parseString(str.encode(), xh)
    return  xh



